import rospy
import time


def time_printer():
    # 循环打印当前时间
    while not rospy.is_shutdown():
        current_time = rospy.get_time()
        rospy.loginfo("Current time: %.2f", current_time)
        time.sleep(1)


if __name__ == '__main__':
    # 初始化ROS节点
    rospy.init_node('time_printer')

    rate = rospy.Rate(1)
    while not rospy.is_shutdown():
        # 启动时间打印循环
        time_printer()

        rate.sleep()
